//
//  XMLVisitorTableViewController.swift
//  Weibo
//
//  Created by mac on 16/5/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class XMLVisitorTableViewController: UITableViewController {
    
    var isLogin = XMLUserAcountViewModel.sharedUserAcountViewModel.isLogin
    var visitorView :XMLVisitorView?
    
    override func loadView() {
        if isLogin {
            super.loadView()
        }else{
        
            visitorView = XMLVisitorView()
//            newView.backgroundColor = UIColor.blueColor()
            view = visitorView
            visitorView!.callBackClosure = { [weak self] in
            
//                print("登录闭包")
//                print(self)
                self?.requestOAuthLogin()
            }
            
            setNavButton()
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        
    }

    private func setNavButton() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", font: 15, target: self, action: "registerButtonClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", font: 15, target: self, action: "loginButtonClick")
    }
    
    @objc private func registerButtonClick() {
    
//        print("registerButtonClick")
        requestOAuthLogin()
    }
    @objc private func loginButtonClick() {
    
//        print("loginButtonClick")
        requestOAuthLogin()
    }
    
    private func requestOAuthLogin() {
    
        let OAuthVC = XMLOAuthViewController()
        let nav = UINavigationController(rootViewController: OAuthVC)
        
        presentViewController(nav, animated: true, completion: nil)
    }

}
